home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Menús / ContextMenuAdd / ContextMenuAdd.cs next >
Encoding:
Text File  |  2002-06-21  |  1.5 KB  |  52 lines

  1. //---------------------------------------------
  2. // ContextMenuAdd.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class ContextMenuAdd: Form
  9. {
  10.      MenuItem miColor;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new ContextMenuAdd());
  15.      }
  16.      public ContextMenuAdd()
  17.      {
  18.           Text = "Men· contextual utilizando Add";
  19.  
  20.           ContextMenu  cm = new ContextMenu();
  21.           EventHandler eh = new EventHandler(MenuColorOnClick);
  22.  
  23.           cm.MenuItems.Add("Negro",    eh);
  24.           cm.MenuItems.Add("Azul",     eh);
  25.           cm.MenuItems.Add("Verde",    eh);
  26.           cm.MenuItems.Add("Celeste",  eh);
  27.           cm.MenuItems.Add("Rojo",     eh);
  28.           cm.MenuItems.Add("Magenta",  eh);
  29.           cm.MenuItems.Add("Amarillo", eh);
  30.           cm.MenuItems.Add("Blanco",   eh);
  31.  
  32.           foreach (MenuItem mi in cm.MenuItems)
  33.                mi.RadioCheck = true;
  34.  
  35.           SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  36.  
  37.           miColor = cm.MenuItems[3];
  38.           miColor.Checked = true;
  39.           BackColor = Color.FromName(miColor.Text);
  40.  
  41.           ContextMenu = cm;
  42.      }
  43.      void MenuColorOnClick(object obj, EventArgs ea)
  44.      {
  45.           miColor.Checked = false;
  46.           miColor = (MenuItem) obj;
  47.           miColor.Checked = true;
  48.  
  49.           BackColor = Color.FromName(miColor.Text);
  50.      }
  51. }
  52.